package command;

/**
 * @author : DuJiabao
 * @Date : 2021/3/16 15:53
 * @Project : design-pattern
 * @File : null.java
 * @Desc :
 */
public class RemoteController {
  Command[] onCommands;
  Command[] offCommands;
  Command undoCommand;

  public RemoteController(int size) {
    onCommands = new Command[size];
    offCommands = new Command[size];

    for (int i = 0; i < size; i++) {
      onCommands[i] = new NoCommand();
      offCommands[i] = new NoCommand();
    }
  }

  public void setCommand(int no, Command onCommand, Command offCommand) {
    onCommands[no] = onCommand;
    offCommands[no] = offCommand;
  }

  public void onButtonWasPushed(int no) {
    onCommands[no].execute();
    undoCommand = onCommands[no];
  }

  public void offButtonWasPushed(int no) {
    offCommands[no].execute();
    undoCommand = offCommands[no];
  }

  public void undoButtonWadPushed() {
    undoCommand.undo();
  }
}
